﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Control_InsertBusCarControl : System.Web.UI.UserControl
{
    ListAndProcessData ws = new ListAndProcessData();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            var a = ws.getTravelPlan();
            var b = ws.getSLocation();
            foreach (var item in b)
            {
                DropDownListstartLocatioon.Items.Add(item.Startlocaion);
            }
            foreach (var item in a)
            {


                DropDownList1.Items.Add(item.EndLocation);
            }

            var c = ws.getBusType();
            foreach (var item1 in c)
            {

                DropDownListBusType.Items.Add(item1.Name);
            }
        }

    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        bool a = false;
        a = ws.InsertBusCar(txtBusNo.Text, txtSeatsUsed.Text, (DropDownListstartLocatioon.SelectedItem).ToString(), (DropDownListBusType.SelectedItem).ToString(), (DropDownList1.SelectedItem).ToString(), DropDownList2.SelectedItem.ToString());
        if (a == true)
        {
            Response.Redirect("ShowBusCar_Admin.aspx");

        }
        else
        {
            Response.Redirect("Default.aspx");
        }
    }
    protected void btnreset_Click(object sender, EventArgs e)
    {

        txtSeatsUsed.Text = "";
        txtBusNo.Text = "";
        DropDownListstartLocatioon.SelectedIndex = 0;
        DropDownListBusType.SelectedIndex = 0;
        DropDownList1.SelectedIndex = 0;
    }
    protected void DropDownListstartLocatioon_SelectedIndexChanged(object sender, EventArgs e)
    {
        var d = ws.getEndLocation((DropDownListstartLocatioon.SelectedItem).ToString());
        DropDownList1.Items.Clear();
        foreach (var item in d)
        {
            DropDownList1.Items.Add(item.Location);
        }
    }
}